﻿namespace date
{/// <summary>
/// 输出本年日历
/// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {
            //输出自己出生多少天
            //TimeSpan ts = DateTime.Today - new DateTime(2003, 11, 26);
            //Console.WriteLine($"从出生到现在已经过了{ts.TotalDays}天");
            //输出本年(2022)日历
            //定义位置变量
            const int monthWidth = 35;
            const int monthHeight = 9;
            const int dayWidth = 4;
            int x = 0, y = 0;
            //定义某一天的变量
            DateTime theDay = new DateTime(2022, 1, 1);

            do
            {
                //得到星期几
                int theDayOfWeek = Convert.ToInt32(theDay.DayOfWeek);
                if (theDay.Day == 1)
                {
                    //确定每个月的位置并输出
                    x = ((theDay.Month - 1) % 3) * monthWidth;
                    y = (theDay.Month - 1) / 3 * monthHeight;
                    Console.SetCursorPosition(x, y);
                    Console.WriteLine("{0,15}月", theDay.Month);
                    //确定星期几的位置
                    y++;
                    Console.SetCursorPosition(x, y);
                    Console.WriteLine("  日  一  二  三  四  五  六  ");
                    //确定每个月1号的位置
                    y++;
                    x = ((theDay.Month - 1) % 3) * monthWidth + theDayOfWeek * dayWidth;
                    Console.SetCursorPosition(x, y);
                    Console.Write("1".PadLeft(dayWidth), ' ');
                }
                //输出其他日期
                //若是周六，则换行输出
                if (theDayOfWeek == 6)
                {
                    x = ((theDay.Month - 1) % 3) * monthWidth + theDayOfWeek * dayWidth;
                    Console.SetCursorPosition(x, y);
                    Console.Write($"{theDay.Day}".PadLeft(dayWidth, ' '));
                    //使光标移动至下一行开始处
                    y++;
                    x -= theDayOfWeek * dayWidth;
                }
                //若非周六，则继续输出
                else
                {
                    Console.SetCursorPosition(x, y);
                    Console.Write($"{theDay.Day}".PadLeft(dayWidth, ' '));
                    //向右移动输出每一天
                    x += dayWidth;
                }
                //y++;
                Console.SetCursorPosition(x, y);
                theDay = theDay.AddDays(1);
            } while (theDay.Year == 2022);
        }
    }
}